<template>
  <div class="pub-body">

    <div class="table-operator">
      <el-button icon="el-icon-back" size="small" class="addBtn" type="primary" @click="goBack">返回</el-button>
      <el-button icon="el-icon-download"  :disabled="state != 3" size="small" class="addBtn" type="primary" @click="handleExportXls('盘点明细表')">导出</el-button>
    </div>

    <div style="width:1000px ;">
      <el-progress
        style="width: 100%;height: 40px;left: 80px;"
        :text-inside="true"
        :stroke-width="20"
        :percentage="percentage"
      ></el-progress>
      <span style="display: block; float: left; margin-top: -40px;">盘点进度</span>
    </div>

    <!-- 资产列表 -->
    <div class="project">
      <el-table
        size="small"
        :data="dataSource"
        border
        style="width: 100%"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      >
        <el-table-column prop="number" fixed width="170" label="资产ID"></el-table-column>
        <el-table-column prop="contractNamber" fixed width="150" label="合同号"></el-table-column>
        <el-table-column prop="batch" width="120" label="批次" sortable></el-table-column>
        <el-table-column prop="inDate" width="120" label="入库日期" sortable></el-table-column>
        <el-table-column prop="name" width="150" label="资产名称" sortable></el-table-column>
        <el-table-column prop="price" width="120" label="价格（元）" sortable></el-table-column>
        <el-table-column width="300" label="规格型号" sortable>
          <template slot-scope="scope">
            <el-tooltip :content="scope.row.model" effect="light">
              <span>{{scope.row.model}}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="buyer" width="180" label="购买单位" sortable></el-table-column>
        <el-table-column label="使用状态">
          <template slot-scope="scope">{{ ['正常','损坏'][scope.row.useState-1] }}</template>
        </el-table-column>
        <el-table-column label="盘点状态">
          <template slot-scope="scope">
             <el-tag v-if="scope.row.itemState == 1" type="info" effect="dark">未盘</el-tag>
             <el-tag v-else type="success" effect="dark">已盘</el-tag>
            <!-- <el-tag :type=type effect="dark">{{ ['未盘','已盘'][scope.row.itemState-1] }}</el-tag>         -->
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="140">
          <template slot-scope="scope">
            <el-button v-if="state == 3"  @click="handleDetail(scope.row)" type="text" size="small">查看</el-button>
            <el-button  v-else @click="handleEdit(scope.row)" type="text" size="small">编辑</el-button>

          </template>
        </el-table-column>
      </el-table>
      <asset-check ref="modalForm" @ok="modalFormOk"></asset-check>
    </div>
  </div>
</template>

<script>
import { SingleTableMixins } from "@/mixins/SingleTableMixins";
import Pagination from "@/components/Pagination";
import assetCheck from "./assetCheck";
import { getAction } from "@/api/manage";

export default {
  name: "check",
  components: { Pagination, assetCheck },
  mixins: [SingleTableMixins],
  data() {
    return {
      state:2,
      url: {
        list: `/inventory/itemsByMainId`,
        exportXlsUrl:'/inventory/exprotXls'
      },
      disableMixinCreated: true,
      percentage: 0,
      data: ''
    };
  },
  created() {

  },

  methods: {
    // loadItem(mainId){
    //   this.url.list = `/inventory/itemsByMainId/${mainId}`;
    //   this.loadData(1);
    //加载盘点jindu
    //this.loadProc
    // },
    //loadPro
    getDataByMain(id,state) {
      let that = this;
      this.state=state;
      this.url.list = `/inventory/itemsByMainId/${id}`;
      this.url.exportXlsUrl = `/inventory/exprotXls/${id}`;
      this.loadData(1);
      getAction(`/inventory/progress/${id}`).then(res => {
        that.percentage = (res.data.completed / res.data.total).toFixed(2) * 100;
      });
    },
    customColorMethod(percentage) {
      if (percentage < 30) {
        return "#909399";
      } else if (percentage < 70) {
        return "#e6a23c";
      } else {
        return "#67c23a";
      }
    },
    goBack(){
      this.$emit("goBack")
    }

  }
};
</script>

<style scoped>
.cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
